package cn.hc.phoenix5;

import java.sql.*;
import java.util.Properties;

/**
 * @author huangchao E-mail:fengquan8866@163.com
 * @version 创建时间：2024/10/10 8:57
 */
public class PhoenixConnection1 {
    public static void main(String[] args) throws SQLException {
        // 标准的jdbc连接
        // 1.url
        String url = "jdbc:phoenix:master,hadoop141,hadoop-test:2181";

        // 2.配置对象 没有用户名、密码
        Properties properties = new Properties();

        // 3.获取连接
        Connection connection = DriverManager.getConnection(url, properties);

        // 4.预编译sql
        PreparedStatement preparedStatement = connection.prepareStatement("select * from student");

        // 5.执行sql
        ResultSet resultSet = preparedStatement.executeQuery();

        // 6.结果打印
        while (resultSet.next()) {
            System.out.print(resultSet.getString(1));
            System.out.print(":");
            System.out.print(resultSet.getString(2));
            System.out.print(":");
            System.out.print(resultSet.getLong(3));
            System.out.print(":");
            System.out.print(resultSet.getString(4));
            System.out.println();
        }

        // 7.关闭连接
        connection.close();
    }
}
